package com.ruoyi.electricity.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.electricity.domain.PersonHealthInfo;
import com.ruoyi.electricity.service.IPersonHealthInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 健康信息检测Controller
 *
 * @author ljw
 * @date 2023-12-10
 */
@RestController
@RequestMapping("/electricity/personHealthDiagnosis")
public class PersonHealthInfoController extends BaseController
{
    @Autowired
    private IPersonHealthInfoService personHealthInfoService;

    /**
     * 查询健康信息检测列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PersonHealthInfo personHealthInfo)
    {
        startPage();
        List<PersonHealthInfo> list = personHealthInfoService.selectPersonHealthInfoList(personHealthInfo);
        return getDataTable(list);
    }

    /**
     * 导出健康信息检测列表
     */
    @Log(title = "健康信息检测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PersonHealthInfo personHealthInfo)
    {
        List<PersonHealthInfo> list = personHealthInfoService.selectPersonHealthInfoList(personHealthInfo);
        ExcelUtil<PersonHealthInfo> util = new ExcelUtil<PersonHealthInfo>(PersonHealthInfo.class);
        util.exportExcel(response, list, "健康信息检测数据");
    }

    /**
     * 获取健康信息检测详细信息
     */
    @GetMapping(value = "/{personId}")
    public AjaxResult getInfo(@PathVariable("personId") Integer personId)
    {
        return success(personHealthInfoService.selectPersonHealthInfoByPersonId(personId));
    }

    /**
     * 新增健康信息检测
     */
    @Log(title = "健康信息检测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PersonHealthInfo personHealthInfo)
    {
        return toAjax(personHealthInfoService.insertPersonHealthInfo(personHealthInfo));
    }

    /**
     * 修改健康信息检测
     */
    @Log(title = "健康信息检测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PersonHealthInfo personHealthInfo)
    {
        return toAjax(personHealthInfoService.updatePersonHealthInfo(personHealthInfo));
    }

    /**
     * 删除健康信息检测
     */
    @Log(title = "健康信息检测", businessType = BusinessType.DELETE)
    @DeleteMapping("/{personIds}")
    public AjaxResult remove(@PathVariable Integer[] personIds)
    {
        return toAjax(personHealthInfoService.deletePersonHealthInfoByPersonIds(personIds));
    }
}
